import { machineManagerMachineGetRunState } from '../../../api/intelligence';
import { systemWorkshopPage } from '../../../api/basicData/workshop';
import { machineStateList } from '../../../utils/jk/status-option-list';

export default {
	data() {
		return {
			colors: ['#FE6D72', '#23B796', 'rgb(161, 92, 253)', '#2d8cf0', '#ff9900', '#FF00FF', '#00FFFF', '#70DB93', '#5C3317', '#9F5F9F', '#B5A642', '#D9D919', '#A62AA2', '#8C7853', '#A67D3D', '#5F9F9F', '#D98719', '#B87333', '#FF7F00', '#42426F', '#5C4033', '#2F4F2F', '#4A766E'],
			machineStateList: machineStateList
		};
	},
	methods: {
		setParentGridStyle(item) {
			return {
				display: 'flex',
				justifyContent: 'center',
				alignItems: 'center',
				fontSize: '12px',
				color: '#fff'
			};
		},
		setGridStyle(item) {
			const stateItem = this.machineStateList.find(x => x.id === item.state) || {};
			return {
				display: 'flex',
				justifyContent: 'center',
				alignItems: 'center',
				fontSize: '12px',
				color: '#fff',
				// borderRadius: item.borderRadius ? `${item.borderRadius}%` : '4px',
				background: stateItem.bgColor ? stateItem.bgColor : '#808695'
				// boxShadow: `0 0 2px 1px ${item.bgColor ? item.bgColor : '#c5c8ce'}`
			};
		},
		getMachineRunStateRequest() {
			return machineManagerMachineGetRunState({ workshopIds: this.allWorkshopList.map(x => x.id) }).then(res => {
				if (res.data.status === 200) {
					this.machineRunStateList = [];
					if (res.data.res) {
						res.data.res.forEach(x => {
							x.machineRunStateList.forEach(k => {
								this.machineRunStateList.push(k);
							});
						});
					}
				}
			});
		},
		getWorkshopListRequest() {
			return systemWorkshopPage().then(res => {
				if (res.data.status === 200) {
					this.allWorkshopList = res.data.res || [];
				}
			});
		}
	}
};
